package cn.com.xinjinfu.pdoulcProduct.activity.user;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.android.volley.RequestQueue;
import cn.com.xinjinfu.pdoulcProduct.R;
import cn.com.xinjinfu.pdoulcProduct.activity.base.BaseActivity;
import cn.com.xinjinfu.pdoulcProduct.entity.User;
import cn.com.xinjinfu.pdoulcProduct.manager.AccountManager;
import cn.com.xinjinfu.pdoulcProduct.manager.TitleManager;
import cn.com.xinjinfu.pdoulcProduct.utils.BankImgUtils;
import cn.com.xinjinfu.pdoulcProduct.utils.ReloadUserInfo;

/**
 * 我的银行卡列表
 * Created by android-adt on 2016/1/21.
 */
public class ActBankControl extends BaseActivity {

    private ListView lv_bank_control;
    private MyAdapter mAdapter;
    private User user;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_bankcard_control);
        //初始化头布局
        TitleManager.showTitle(this, "银行卡", "");
        user = AccountManager.getInstance().getUser();
        lv_bank_control = (ListView) findViewById(R.id.lv_bank_control);
        mAdapter = new MyAdapter(this);
        lv_bank_control.setAdapter(mAdapter);

        //刷新user信息
        new ReloadUserInfo(this).userRequest();
    }



    private class MyAdapter extends BaseAdapter {
        private LayoutInflater mInflater;

        public MyAdapter(Context context) {
            this.mInflater = LayoutInflater.from(context);
        }
        @Override
        public int getCount() {
            return 1;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = mInflater.inflate(R.layout.item_bankcard_list, null);
            TextView tv_bank_name = (TextView) convertView.findViewById(R.id.tv_bank_name);
            TextView tv_bankcart_num = (TextView) convertView.findViewById(R.id.tv_bankcart_num);
            ImageView img_bankcard = (ImageView) convertView.findViewById(R.id.img_bankcard);
            GradientDrawable myGrad = (GradientDrawable)tv_bank_name.getBackground();
            if (user != null) {
                tv_bank_name.setText(user.getBank_name());
                String id = user.getAccount();
                if (id != null && !id.equals("")) {
                    String show_id = "**** **** **** " + id.substring(id.length() - 4);
                    tv_bankcart_num.setText(show_id);
                }else {
                    tv_bankcart_num.setText("**** **** ****");
                }
                int x = new BankImgUtils().mBank(false,user.getBank_code());
                img_bankcard.setImageResource(x);
                int y = new BankImgUtils().mBank(true,user.getBank_code());
                myGrad.setColor(y);
            }
            return convertView;
        }
    }
}
